<?php
require './include/global.php';
require './include/validate.php';

if($_POST["action"] == "jobedit_ajax") {
	$jo_id = (int)$_POST["id"];
	$rs  = $DB->fetch_one_array("SELECT jo_bonus FROM pa_job WHERE `jo_uid`=".$_SESSION[uid]." AND `jo_id` =".$jo_id );

	$jo_bonus = date("M d, Y")." --------------\r".mysql_escape_string($_POST["jo_bonus"])."\r\r".$rs["jo_bonus"];
	$sql = "UPDATE pa_job SET jo_bonus = '".$jo_bonus."' WHERE `jo_uid`=".$_SESSION[uid]." AND `jo_id` =".$jo_id;
	$DB->query($sql);
	$return_array = array("status"=>1, "text"=>nl2br($jo_bonus));
	echo json_encode($return_array);
	exit;
}

//Not A Recuiter
if($_SESSION[usertype] != "recruiter" ){
   echo "<meta http-equiv=\"refresh\" content=\"0;URL=errorall.php?errid=rc_1011\">";
   exit;	
}
$senderuid = $_SESSION['uid']+0;
$touid = $_POST['rid']+0;

//check if you can send the email 
$sql = "SELECT COUNT(*) as count FROM pa_email WHERE e_isreplied = 0 AND e_sentrcid='".$senderuid."' AND e_receivedrcid='".$touid."' AND e_sendertype = 'recruiter' AND  e_receivertype = 'recruiter' AND e_type = '3' ";
$checkNum = $DB->fetch_one_array($sql);
if( $checkNum['count'] > 0 ){
	$return_array = array("status"=>0, "text"=>"<div style='padding:20px'><span style='color:#FF8C00;font-weight:bolder;font-size:18px'>Congratulations! </span><br>Your invitation to connect has been successfully sent!</div>");
	echo json_encode($return_array);
	exit;
}

$sql = " SELECT * FROM pa_recuiter WHERE rc_id = '".$touid."' ";
$toRecInfo = $DB->fetch_one_array($sql);
$message = nl2br(str_replace('Include a personal message (optional)','',$_POST['message']));
//Save Email

$sql = " INSERT INTO pa_email (
	`e_sentrcid`,
	`e_receivedrcid`,
	`e_fromemail`,
	`e_fromname`,
	`e_sendertype`,
	`e_receivertype`,
	`e_type`,
	`e_toemail`,
	`e_toname`,
	`e_subject`,
	`e_content`,
	`e_created`							
) VALUES (
	 '".$senderuid."',
	 '".$touid."',
	 '".$_SESSION['useremail']."',
	 '".$_SESSION['realname']."',
	 'recruiter',
	 'recruiter',
	 '3',
	 '".$toRecInfo['rc_email']."',
	 '".$toRecInfo['rc_fname']." ".$toRecInfo['rc_lname']."',
	 'Invitation to Connect',
	 '".$message."',
	'".time()."'
)";


$DB->query($sql);

$return_array = array("status"=>1, "text"=>"<div style='padding:20px'><span style='color:#FF8C00;font-weight:bolder;font-size:18px'>Congratulations! </span><br>Your invitation to connect has been successfully sent!</div>");
echo json_encode($return_array);
exit;

$content = stripslashes($message). "<br><br>";
$content .= 'To view and respond to this invitation, please Sign In to your account at http://www.enetrecruiter.com</a>'."<br><br>";
$content .= '<span style="color:gray;">Connect on <font color="orange">enetRecruiter</font> to achieve greater recruiting success.  Register for a free account today at <a href="http://www.enetrecruiter.com/">enetRecruiter.com</a></span>'."<br><br>";
$content .= '<span style="color:gray;">NOTE: This message was sent to you by a member of enetRecruiter.com. Please do not reply to this message. To reply to the sender, please sign-in to your account on enetRecruiter or create an account if you are not yet a member. For all questions, please contact us at <a href="mailto:account@enetrecruiter.com">account@enetrecruiter.com</a>. Wishing you many recruiting success!</span>'. "<br><br>";


//Send Email
require_once("./include/class.phpmailer.php");
$mail=new PHPMailer();
$toName = $toRecInfo['rc_fname']." ".$toRecInfo['rc_lname'];

$mail->IsMail();
$mail->From     = "noreply@enetrecruiter.com";
$mail->FromName = $_SESSION['realname'];

$mail->IsHTML(true);
$mail->Subject = "Connect with me on enetRecruiter";
$mail->Body = $content;

$mail->CharSet = 'UTF-8';

$mail->AddAddress($toRecInfo['rc_email'],$toRecInfo['rc_fname']." ".$toRecInfo['rc_lname']);

$mail->Send();

exit;

?>
